package com.example.easybuy.controller;

import com.example.easybuy.service.LoginService;
import com.example.easybuy.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
public class LoginController {
    private LoginService loginService;

    @Autowired
    public LoginController(LoginService loginService) {
        this.loginService = loginService;
    }

    @PostMapping("/login")
    public AjaxResult login(@RequestBody Map<String, String> params) {
        Map<String, Object> map = loginService.login(params.get("loginName"), params.get("password"));
        return AjaxResult.success().add("token", map.get("jwt").toString()).add("loginName", map.get("loginName").toString());//在添加type等信息
    }
}